package com.mojo.jvm.lock;

import java.util.concurrent.locks.ReentrantLock;

/**
 * 锁的内存语义实现
 *
 * @author <a href="mailto:sjj@jianzhimao.com">mojo</a>
 * copyright (C), 2013-2022, 广州九尾信息科技有限公司
 * @date 2022/10/24 10:45
 */
public class LockDemo {
    ReentrantLock lock = new ReentrantLock();
    int n = 0;

    public void read() {
        lock.lock();
        try {
            System.out.println(Thread.currentThread().getName() + ">>>" + n);
        } finally {
            lock.lock();
        }
    }

    public void writer() {
        lock.lock();
        try {
            n++;
        } finally {

            lock.unlock();
        }
    }

    public static void main(String[] args) {

    }
}
